package com.uex.dev.manage.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.query.MPJQueryWrapper;
import com.google.common.base.Preconditions;
import com.uex.dev.manage.admin.dao.ModelUhubDao;
import com.uex.dev.manage.admin.po.ModelUhubPO;
import com.uex.dev.manage.admin.service.IModelUhubService;
import com.uex.dev.manage.admin.vo.device.UhubInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 云盾型号默认能力 服务实现类
 * </p>
 *
 * @author wangchao
 * @since 2024-04-11
 */
@Service
public class ModelUhubServiceImpl extends ServiceImpl<ModelUhubDao, ModelUhubPO> implements IModelUhubService {

    @Override
    public UhubInfo getUhubFeature(Integer modelId) {
        UhubInfo uhubInfo = this.selectJoinOne(UhubInfo.class, new MPJQueryWrapper<ModelUhubPO>()
                .select("t.*, tdm.device_model")
                .leftJoin("t_device_model tdm on tdm.id = t.model_id")
                .eq("t.model_id", modelId));
        Preconditions.checkArgument(Objects.nonNull(uhubInfo), "型号Id不存在");
        return uhubInfo;
    }

    @Override
    public void updateUhubFeature(UhubInfo uhubModelUpdateReq) {
        ModelUhubPO modelUhub = uhubModelUpdateReq.toModelUhubPO();
        Preconditions.checkArgument(this.updateById(modelUhub), "型号Id不存在");
    }

    @Override
    public List<UhubInfo> getUhubFeatureList() {
        return this.selectJoinList(UhubInfo.class, new MPJQueryWrapper<ModelUhubPO>()
                .select("t.*,tdm.device_model")
                .leftJoin("t_device_model tdm on tdm.id = t.model_id"));
    }
}
